home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / lib / calc / cmath.h < prev    next >
C/C++ Source or Header  |  1995-07-17  |  4KB  |  110 lines

  1. /*
  2.  * Copyright (c) 1993 David I. Bell
  3.  * Permission is granted to use, distribute, or modify this source,
  4.  * provided that this copyright notice remains intact.
  5.  *
  6.  * Data structure declarations for extended precision complex arithmetic.
  7.  */
  8.  
  9. #ifndef    CMATH_H
  10. #define    CMATH_H
  11.  
  12. #include "qmath.h"
  13.  
  14.  
  15. /*
  16.  * Complex arithmetic definitions.
  17.  */
  18. typedef struct {
  19.     NUMBER *real;        /* real part of number */
  20.     NUMBER *imag;        /* imaginary part of number */
  21.     long links;        /* link count */
  22. } COMPLEX;
  23.  
  24.  
  25. /*
  26.  * Input, output, and conversion routines.
  27.  */
  28. extern COMPLEX *comalloc MATH_PROTO((void));
  29. extern COMPLEX *qqtoc MATH_PROTO((NUMBER *q1, NUMBER *q2));
  30. extern void comfree MATH_PROTO((COMPLEX *c));
  31. extern void comprint MATH_PROTO((COMPLEX *c));
  32. extern void cprintfr MATH_PROTO((COMPLEX *c));
  33.  
  34.  
  35. /*
  36.  * Basic numeric routines.
  37.  */
  38. extern COMPLEX *cadd MATH_PROTO((COMPLEX *c1, COMPLEX *c2));
  39. extern COMPLEX *csub MATH_PROTO((COMPLEX *c1, COMPLEX *c2));
  40. extern COMPLEX *cmul MATH_PROTO((COMPLEX *c1, COMPLEX *c2));
  41. extern COMPLEX *cdiv MATH_PROTO((COMPLEX *c1, COMPLEX *c2));
  42. extern COMPLEX *caddq MATH_PROTO((COMPLEX *c, NUMBER *q));
  43. extern COMPLEX *csubq MATH_PROTO((COMPLEX *c, NUMBER *q));
  44. extern COMPLEX *cmulq MATH_PROTO((COMPLEX *c, NUMBER *q));
  45. extern COMPLEX *cdivq MATH_PROTO((COMPLEX *c, NUMBER *q));
  46. extern COMPLEX *cmodq MATH_PROTO((COMPLEX *c, NUMBER *q));
  47. extern COMPLEX *cquoq MATH_PROTO((COMPLEX *c, NUMBER *q));
  48. extern COMPLEX *cscale MATH_PROTO((COMPLEX *c, long i));
  49. extern COMPLEX *cshift MATH_PROTO((COMPLEX *c, long i));
  50. extern COMPLEX *cround MATH_PROTO((COMPLEX *c, long i));
  51. extern COMPLEX *cbround MATH_PROTO((COMPLEX *c, long i));
  52. extern COMPLEX *csquare MATH_PROTO((COMPLEX *c));
  53. extern COMPLEX *cconj MATH_PROTO((COMPLEX *c));
  54. extern COMPLEX *creal MATH_PROTO((COMPLEX *c));
  55. extern COMPLEX *cimag MATH_PROTO((COMPLEX *c));
  56. extern COMPLEX *cneg MATH_PROTO((COMPLEX *c));
  57. extern COMPLEX *cinv MATH_PROTO((COMPLEX *c));
  58. extern COMPLEX *cint MATH_PROTO((COMPLEX *c));
  59. extern COMPLEX *cfrac MATH_PROTO((COMPLEX *c));
  60. extern BOOL ccmp MATH_PROTO((COMPLEX *c1, COMPLEX *c2));
  61.  
  62.  
  63. /*
  64.  * More complicated functions.
  65.  */
  66. extern COMPLEX *cpowi MATH_PROTO((COMPLEX *c, NUMBER *q));
  67. extern HASH chash MATH_PROTO((COMPLEX *c));
  68.  
  69.  
  70. /*
  71.  * Transcendental routines.  These all take an epsilon argument to
  72.  * specify how accurately these are to be calculated.
  73.  */
  74. extern COMPLEX *cpower MATH_PROTO((COMPLEX *c1, COMPLEX *c2, NUMBER *epsilon));
  75. extern COMPLEX *csqrt MATH_PROTO((COMPLEX *c, NUMBER *epsilon));
  76. extern COMPLEX *croot MATH_PROTO((COMPLEX *c, NUMBER *q, NUMBER *epsilon));
  77. extern COMPLEX *cexp MATH_PROTO((COMPLEX *c, NUMBER *epsilon));
  78. extern COMPLEX *cln MATH_PROTO((COMPLEX *c, NUMBER *epsilon));
  79. extern COMPLEX *ccos MATH_PROTO((COMPLEX *c, NUMBER *epsilon));
  80. extern COMPLEX *csin MATH_PROTO((COMPLEX *c, NUMBER *epsilon));
  81. extern COMPLEX *cpolar MATH_PROTO((NUMBER *q1, NUMBER *q2, NUMBER *epsilon));
  82.  
  83.  
  84. /*
  85.  * macro expansions to speed this thing up
  86.  */
  87. #define cisreal(c)    (qiszero((c)->imag))
  88. #define cisimag(c)    (qiszero((c)->real) && !cisreal(c))
  89. #define ciszero(c)    (cisreal(c) && qiszero((c)->real))
  90. #define cisone(c)    (cisreal(c) && qisone((c)->real))
  91. #define cisnegone(c)    (cisreal(c) && qisnegone((c)->real))
  92. #define cisrunit(c)    (cisreal(c) && qisunit((c)->real))
  93. #define cisiunit(c)    (qiszero((c)->real) && qisunit((c)->imag))
  94. #define    cisunit(c)    (cisrunit(c) || cisiunit(c))
  95. #define cistwo(c)    (cisreal(c) && qistwo((c)->real))
  96. #define cisint(c)    (qisint((c)->real) && qisint((c)->imag))
  97. #define ciseven(c)    (qiseven((c)->real) && qiseven((c)->imag))
  98. #define cisodd(c)    (qisodd((c)->real) || qisodd((c)->imag))
  99. #define clink(c)    ((c)->links++, (c))
  100.  
  101.  
  102. /*
  103.  * Pre-defined values.
  104.  */
  105. extern COMPLEX _czero_, _cone_, _conei_;
  106.  
  107. #endif
  108.  
  109. /* END CODE */
  110.